/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package BUS;

import DAO.Task2DAO;
import DTO.Task2DTO;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author trquanglong
 */
public class Task2BUS {

    /**
     * Add one task to Database
     * @param _task
     */
    public static void addTaskToDB(Task2DTO _task) {
        try {
            Task2DAO.addTaskToDB(_task);
        } catch (SQLException ex) {
            Logger.getLogger(Task2BUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(Task2BUS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * delete One Task from table Tasks2 with condition: data = task
     * @param task
     */
    public static void deleteOneTask(Task2DTO task) {
        try {
            Task2DAO.deleteOneTask(task);
        } catch (SQLException ex) {
            Logger.getLogger(Task2BUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(Task2BUS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Get all of task from table Task2
     * Return a list of tasks
     * @return
     */
    public static ArrayList<Task2DTO> getListTask(){
        ArrayList<Task2DTO> lstTask = new ArrayList<Task2DTO>();
        try {
            lstTask = Task2DAO.getListTask();
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(Task2BUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Task2BUS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lstTask;

    }

    /**
     * Update all of task
     * Delete all of task in table Task2
     * Add tasks of lstTask
     * @param lstTask
     */
    public static void updateAllTask(ArrayList<Task2DTO> lstTask) {
        try {
            Task2DAO.updateAllTask(lstTask);
        } catch (SQLException ex) {
            Logger.getLogger(Task2BUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(Task2BUS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
